package com.googlecode.wheres_my_stuff_okay_potato;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.widget.DatePicker;

/**
 * A fragment that brings up a dialog box containing a date picker a user can
 * filter a list of items by.
 * 
 * @author Jeremy Hehn
 */
public class DatePickerFragment extends DialogFragment implements
		DatePickerDialog.OnDateSetListener {
	private Calendar date;

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		date = Calendar.getInstance();
		int year = date.get(Calendar.YEAR);
		int month = date.get(Calendar.MONTH);
		int day = date.get(Calendar.DAY_OF_MONTH);

		// Create a new instance of DatePickerDialog and return it
		return new DatePickerDialog(getActivity(), this, year, month, day);
	}

	@Override
	public void onDateSet(DatePicker view, int year, int month, int day) {
		// This method is called when the user presses okay
		date.set(year, month, day);
	}

	/**
	 * Returns the currently selected date.
	 * 
	 * @return the date the user most recently selected.
	 */
	public Calendar getDate() {
		return date;
	}
}